package com.tarena.lbs.article.web.controller;

import com.tarena.lbs.article.web.service.ArticleService;
import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.pojo.content.param.ArticleContentParam;
import com.tarena.lbs.pojo.content.query.ArticleQuery;
import com.tarena.lbs.pojo.content.vo.ArticleCategoryVO;
import com.tarena.lbs.pojo.content.vo.ArticleVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.print.attribute.standard.PageRanges;
import java.io.IOException;
import java.util.HashSet;

@RestController
@Slf4j
public class ArticleController {
    @Autowired
    private ArticleService articleService;
    @GetMapping("/admin/content/article/list")
    public Result<PageResult<ArticleVO>> articlePages(ArticleQuery query)
        throws BusinessException{
        PageResult<ArticleVO> voPages= articleService.articlePages(query);
        return new Result<>(voPages);
    }
    @GetMapping("/admin/content/category/list")
    public Result<PageResult<ArticleCategoryVO>> categoryPages(ArticleQuery query)
        throws BusinessException{
        PageResult<ArticleCategoryVO> voPages= articleService.categoryPages(query);
        return new Result<>(voPages);
    }
    //新增推送文章
    @PostMapping("/admin/content/article/insert")
    public Result<Void> articleAdd(ArticleContentParam param)
        throws BusinessException{
        articleService.articleAdd(param);
        log.info("新增文章入参:{}",param);
        return Result.success();
    }
    @GetMapping("/admin/content/article/getArticleLabel")
    public Result<HashSet<String>> articleLabels(ArticleQuery articleQuery)
            throws BusinessException, IOException {
        HashSet<String> labels=articleService.articleLabels(articleQuery);
        return new Result<>(labels);
    }
    //获取文章详情
    @GetMapping("/admin/content/article/get")
    public Result<ArticleVO> articleDetail(String id){
        ArticleVO vo=articleService.articleDetail(id);
        return new Result<>(vo);
    }
































}
